import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		if(args.length != 1) {
			System.err.println("Usage: java -jar SpellChecker.jar <text_file>");
			System.exit(1);
		}
		
		try {
			Dictionary dictionary = new Dictionary("dictionary.txt");
			
			BufferedReader in = new BufferedReader(new FileReader(args[0]));
			String line;
			int lineCount = 0;
			while((line = in.readLine()) != null) {
				lineCount++;
				StringTokenizer tok = new StringTokenizer(line);
				int wordCount = 0;
				while(tok.hasMoreTokens()) {
					wordCount++;
					String word = tok.nextToken();
					if(!dictionary.contains(word)) {
						List<Suggestion> suggestions = dictionary.getSuggestions(word, 4);
						System.out.println(
								word + " (L" + lineCount + ":W" + wordCount + ") did you mean: " +
								suggestions
						);
					}
				}
			}
			in.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
}
